package com.ztt.main;

import java.io.File;

import com.google.gson.Gson;
import com.ztt.Config;
import com.ztt.model.taobao.TBProductModel;
import com.ztt.service.taobao.AnalyizeTBDataService;
import com.ztt.utils.FileUtils;

/**
 * 淘宝商品详情抓取测试
 * 
 * @author apple
 * 
 */
public class TaobaoerTest {
	// https://item.taobao.com/item.htm?id=521625072690
	// https://item.taobao.com/item.htm?id=521105483650
	// https://item.taobao.com/item.htm?id=520731323472
	public static void main(String[] args) {
		String mUrl = "https://item.taobao.com/item.htm?id=521105483650";
		// 进行文件存放目录创建
		createDirectory();
		AnalyizeTBDataService mAnalyticalDataService = new AnalyizeTBDataService(
				mUrl);
		try {
			// 进行数据抓取
		 TBProductModel tbProductModel=mAnalyticalDataService.getDataService();
		 System.out.println("数据抓取成功...");
		 FileUtils.saveDataToLog(new Gson().toJson(tbProductModel));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 进行本地服务器 文件存放地址 路径目录
	 */
	public static void createDirectory() {
		File rootPath = new File(Config.ROOT_PATH);
		if (!rootPath.exists()) {
			rootPath.mkdirs();
		}
		if (rootPath.exists()) {
			File image_directory = new File(rootPath, Config.IMAGE_DIRECTORY);
			if (!image_directory.exists()) {
				image_directory.mkdirs();
			}
		}
	}
}
